package com.hex.ds.hdtp.core.inf.metadata.service.impl;

import cn.hutool.core.util.StrUtil;
import com.hex.ds.hdtp.core.inf.metadata.entity.TableFieldsEntity;
import com.hex.ds.hdtp.core.inf.metadata.repository.ISourceConfInfoRepository;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Package com.hex.ds.hdtp.core.inf.metadata.service.impl
 * @ClassName ODPSMethodService
 * @Description ODPS元数据管理服务类
 * @Author gj.xu
 * @Date 2024/3/4 18:21
 * @Version v2.0
 **/
@Service("ODPS")
public class ODPSMethodService extends AbstractSourceMethodService {

    public ODPSMethodService(ISourceConfInfoRepository sourceConfInfoRepository) {
        super(sourceConfInfoRepository);
    }



    @Override
    protected String queryProceduresContentSql(String schemaName, String proceduresName) {
        throw new RuntimeException("ODPS 暂未支持获取存储过程");
    }

    @Override
    protected String getProcedureContentFromResultSet(ResultSet resultSet) throws SQLException {
        throw new RuntimeException("ODPS 暂未支持获取存储过程");
    }

    @Override
    protected TableFieldsEntity toTableFieldsBean(Map<String, String> tableFieldsMap) {
        return null;
    }

    @Override
    protected String queryTableStructureSql(String schemaName, String tableName) {
        return null;
    }

    /**
     * @Method getTablePartitionFieldSql
     * @Param schema
     * @Param table
     * @Return java.lang.String
     * @Description 获取分区字段的SQL
     * @Author gj.xu
     * @Date 2024/2/1 20:20
     * @Version V2.0
     */
    @Override
    public String getTablePartitionFieldSql(String schema, String table) {
        String querySql = "SHOW PARTITIONS {}.{} ";
        return StrUtil.format(querySql, schema, table);
    }

    /**
     * @Method getStrDataType
     * @Param
     * @Return java.util.List<java.lang.String>
     * @Description 获取字符数据类型
     * @Author gj.xu
     * @Date 2024/2/21 14:20
     * @Version V2.0
     */
    @Override
    public List<String> getStrDataType() {
        return Arrays.asList("CHAR", "VARCHAR", "STRING");
    }

    /**
     * @Method getNumDataType
     * @Param
     * @Return java.util.List<java.lang.String>
     * @Description 获取数值数据类型
     * @Author gj.xu
     * @Date 2024/2/21 15:10
     * @Version V2.0
     */
    @Override
    public List<String> getNumDataType() {
        return Arrays.asList("TINYINT", "SMALLINT", "INT", "BIGINT", "FLOAT", "DOUBLE", "DECIMAL");
    }

    /**
     * @Method getAccuracyDataType
     * @Param
     * @Return java.util.List<java.lang.String>
     * @Description 获取精度数据类型
     * @Author gj.xu
     * @Date 2024/2/21 15:32
     * @Version V2.0
     */
    @Override
    public List<String> getAccuracyDataType() {
        return Arrays.asList("DECIMAL");
    }
}
